package com.information.manage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.information.manage.basic.common.result.Result;
import com.information.manage.model.entity.AddFileDO;
import com.information.manage.model.query.AddFileQuery;
import com.information.manage.model.vo.AllStatisticVO;
import com.information.manage.service.AddFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Api(tags = "文件收录")
@RestController
@RequestMapping("/add/file")
public class AddFileController {

    @Resource
    private AddFileService addFileService;

    @GetMapping("/query/page")
    @ApiOperation(value = "分页查询", notes = "分页查询")
    public Result<Page<AddFileDO>> queryPage(AddFileQuery addFileQuery) {
        return addFileService.queryPage(addFileQuery);
    }

    @PostMapping("/upload")
    @ApiOperation(value = "上传", notes = "上传")
    public Result<List<AddFileDO>> handleFileUpload(HttpServletRequest request
            , @RequestParam("archives") List<MultipartFile> archives
            , @RequestParam("listenFileTypeCode") Integer listenFileTypeCode) {
        return addFileService.handleFileUpload(archives, listenFileTypeCode, request);
    }

    @GetMapping("/upload/statistic")
    @ApiOperation(value = "上传统计(最近x天的)", notes = "上传统计(最近x天的)")
    public Result<List<AllStatisticVO>> uploadStatistic(@RequestParam(required = false, defaultValue = "7") Integer days, @RequestParam(required = false) Integer type){
        return addFileService.uploadStatistic(days, type);
    }

}
